package com.nju.bean.cloud;

import java.util.ArrayList;

public class RainManager {
	ArrayList<Dot> dotList;
	ArrayList<Rain> rainList;
	ArrayList<Rain> diedRainList;
	double distance;;
	
	RainManager(ArrayList<Dot> dl,ArrayList<Rain> rl,double dis){
		dotList = dl;
		rainList = rl;
		distance = dis;
	}
	
	void ckeckRain(){
		for(int count = 0;count < rainList.size();count++){
			
			Rain rain = rainList.get(count);
			
			Dot d = new Dot(rain.ps_x,rain.ps_y,null);
			
			dotList.add(d);
			
			int size = d.getCloud(dotList, distance).size();
			if(size<rain.cloudSize*0.5){
				killRain(rain);
				count--;
			}
			else{
				updateRain(rain);
			}
			
			dotList.remove(d);
		}
	}
	void killRain(Rain rain){
		rainList.remove(rain);
		diedRainList.add(rain);
	}
	void updateRain(Rain rain){
		Dot center = Dot.getCenter(dotList);
		rain.ps_x = center.getPs_x();
		rain.ps_y = center.getPs_y();
	}
	
	public ArrayList<Rain> getRain(Dot dot,ArrayList<Dot> dl,double distance){
		ArrayList<Rain> result = new ArrayList<Rain>();
		for(Rain rain:rainList){
			Dot d = new Dot(rain.ps_x,rain.ps_y,null);
			dotList.add(d);
			if(dot.inACloud(d, dotList, distance))
				result.add(rain);
			dotList.remove(d);
		}
		return result;
	}
	
}
